package com.aqie.security.demo.config;

import com.aqie.security.demo.properties.SecurityConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

/**
 * @Function:
 * @Author: aqie
 * @Date: 2019/4/6 8:28
 */
public class AbstractChannelSecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    protected AuthenticationSuccessHandler aqieAuthenticationSuccessHandler;

    @Autowired
    protected AuthenticationFailureHandler aqieAuthenticationFailureHandler;

    protected void applyPasswordAuthenticationConfig(HttpSecurity http) throws Exception {
        http.formLogin()
                .loginPage(SecurityConstants.DEFAULT_UNAUTHENTICATION_URL)          // 配置登录路径 处理不同类型请求,之前写死login.html
                .loginProcessingUrl(SecurityConstants.DEFAULT_LOGIN_PROCESSING_URL_FORM)        // 表单提交 之前是login
                .successHandler(aqieAuthenticationSuccessHandler)
                .failureHandler(aqieAuthenticationFailureHandler);
    }
}
